package cn.lili.event.impl;

import cn.lili.common.utils.StringUtils;
import cn.lili.event.AfterSaleStatusChangeEvent;
import cn.lili.event.OrderStatusChangeEvent;
import cn.lili.modules.goods.entity.enums.SalesModeEnum;
import cn.lili.modules.order.aftersale.entity.dos.AfterSale;
import cn.lili.modules.order.order.client.OrderClient;
import cn.lili.modules.order.order.client.OrderItemClient;
import cn.lili.modules.order.order.entity.dos.Order;
import cn.lili.modules.order.order.entity.dos.OrderItem;
import cn.lili.modules.order.order.entity.dto.OrderMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 供应商业务
 *
 * @author liushuai(liushuai711 @ gmail.com)
 * @version v4.0
 * @Description:
 * @since 2023/3/8 9:16
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class SupplierExecute implements OrderStatusChangeEvent, AfterSaleStatusChangeEvent {


    private final OrderClient orderClient;

    private final OrderItemClient orderItemClient;


    @Override
    public void orderChange(OrderMessage orderMessage) {

        Order order = orderClient.getBySn(orderMessage.getOrderSn());
        if (!SalesModeEnum.PROXY.name().equals(order.getSaleModelType())) {
            return;
        }
        switch (orderMessage.getNewStatus()) {
            //已付款
            case PAID:
                List<OrderItem> orderItemList = orderItemClient.getByOrderSn(orderMessage.getOrderSn());
                for (OrderItem orderItem : orderItemList) {
                    if (StringUtils.isEmpty(orderItem.getSupplierId())) {
                        continue;
                    }
                    String supplierSkuId = orderItem.getSupplierSkuId();
//                    SupplierGoodsSku supplierGoodsSku = supplierGoodsSkuClient.getSku(supplierSkuId);
//                    supplierGoodsSku.getPrice();
                }
                break;
            // 待发货
            case UNDELIVERED:
                //todo 给供应商发消息，让供应商发货
                break;
            //已完成
            case COMPLETED:
                break;
            //默认
            default:
                break;
        }


    }

    @Override
    public void afterSaleStatusChange(AfterSale afterSale) {

    }
}
